package com.gujia.concurrent.future;

import com.sun.corba.se.impl.orbutil.closure.Future;

import java.util.concurrent.*;

public class FutureDemo {

    public static void main(String[] args){
        ExecutorService service = Executors.newCachedThreadPool();

        FutureTask<String> task = new FutureTask<String>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return Thread.currentThread().getName();
            }
        });


        service.execute(task);

        try {
          String res =   task.get();
          System.out.println("res->"+res);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        service.shutdown();

    }
}
